package com.kun.leave.controller;

import com.kun.leave.model.AskForLeaveVO;
import com.kun.leave.model.RespBean;
import com.kun.leave.model.TaskVO;
import com.kun.leave.model.User;
import com.kun.leave.service.AskForLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author fangkun
 * @create 2023-05-26-14:18
 */
@RestController
public class AskForLeaveController {

    @Autowired
    AskForLeaveService askForLeaveService;

    @PostMapping("askForLeave")
    public RespBean askForLeave(@RequestBody AskForLeaveVO askForLeaveVO){
        return askForLeaveService.askForLeave(askForLeaveVO);
    }

    @GetMapping("/users")
    public List<User> getAllUsers(){
        return askForLeaveService.getAllUsers();
    }

    @GetMapping("/unapprove")
    public List<AskForLeaveVO> getUnapproveProcess(){
        return askForLeaveService.getUnapproveProcess();
    }

    @GetMapping("/image/{processId}")
    public void processImage(@PathVariable String processId, HttpServletResponse response) throws IOException {
        askForLeaveService.processImage(processId,response);
    }

    @GetMapping("/tasks")
    public List<TaskVO> getCurrentUserTask(){
        return askForLeaveService.getCurrentUserTask();
    }

    @PostMapping("/approve")
    public RespBean approve(@RequestBody TaskVO taskVO) {
        return askForLeaveService.approve(taskVO);
    }


    @GetMapping("/history")
    public List<AskForLeaveVO> geHistoryProcess() {
        return askForLeaveService.geHistoryProcess();
    }
}
